﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Uow;
using DualControl.Application.Organizations.Dto;
using DualControl.Common;
using DualControl.Organizations;
using DualControl.Posts;
using DualControl.Posts.Dtos;

namespace DualControl.CommonServices
{

    /// <summary>
    /// 视图中使用下拉列表中的数据，包括岗位列表、部门列表、风险级别、颜色、事故类型
    /// 类型为Dictionary<int,string>，前为Key，后为Value
    /// </summary>
    public class CommonService : DualControlAppServiceBase,ICommonService
   {

        private readonly OrganizationUnitAppService _organizationUnitAppService;
        private readonly IPostAppService _postAppService;
        public CommonService(OrganizationUnitAppService organizationUnitAppService, PostAppService postAppService)
        {
            _organizationUnitAppService = organizationUnitAppService;
            _postAppService = postAppService;
        }

        //危险作业场所
       public Dictionary<int,string> HazardousWorkPlaceTypes()
        {
            Dictionary<int, string> hazardousworkplacelist = new Dictionary<int, string>();
            Array keys = Enum.GetValues(typeof(HazardousWorkPlaceType));
            string[] values = Enum.GetNames(typeof(HazardousWorkPlaceType));

            for (int i = 0; i < keys.Length; i++)
            {
                hazardousworkplacelist.Add((int)keys.GetValue(i), values[i]);
            }
            return hazardousworkplacelist;
        }


        //风险颜色
        public Dictionary<int,string> RiskColors()
        {
            Dictionary<int,string> Colorlist = new Dictionary< int,string>();
             Array keys =Enum.GetValues(typeof(RiskColor));
            string[] values =  Enum.GetNames(typeof(RiskColor));

            for (int i = 0; i < keys.Length; i++)
            {
                Colorlist.Add((int)keys.GetValue(i),values[i]);
            }          
            return Colorlist;
        }

        //风险级别
        public Dictionary<int, string> RiskLevels()
        {
            Dictionary<int, string> RiskLevellist = new Dictionary<int, string>();
           Array keys = Enum.GetValues(typeof(RiskLevel));
             string[] values = Enum.GetNames(typeof(RiskLevel));

            for (int i = 0; i < keys.Length; i++)
            {
                RiskLevellist.Add((int)keys.GetValue(i), values[i]);
            }           
            return RiskLevellist;
        }


        /// <summary>
        /// RiskFactorType
        /// </summary>
        /// <returns></returns>
        /// 

        public Dictionary<int, string> RiskFactorType()
        {
            Dictionary<int, string> RiskFactorTypelist = new Dictionary<int, string>();
            Array keys = Enum.GetValues(typeof(RiskFactorType));
            string[] values = Enum.GetNames(typeof(RiskFactorType));

            for (int i = 0; i < keys.Length; i++)
            {
                RiskFactorTypelist.Add((int)keys.GetValue(i), values[i]);
            }
            return RiskFactorTypelist;

        }


        public Dictionary<int, string> AccidentTypes()
        {
            Dictionary<int, string> AccidentTypelist = new Dictionary<int, string>();
           Array keys = Enum.GetValues(typeof(AccidentType));
             string[] values = Enum.GetNames(typeof(AccidentType));

            for (int i = 0; i < keys.Length; i++)
            {
                AccidentTypelist.Add((int)keys.GetValue(i), values[i]);
            }
            return AccidentTypelist;
        }

        //排查周期
        public Dictionary<int,string > GetCheckCycle()
        {
            Dictionary<int, string> CheckCyclelist = new Dictionary<int, string>();
            Array keys = Enum.GetValues(typeof(CheckCycle));
            string[] values = Enum.GetNames(typeof(CheckCycle));

            for (int i = 0; i < keys.Length; i++)
            {
                CheckCyclelist.Add((int)keys.GetValue(i), values[i]);
            }
            return CheckCyclelist;
        }


        //返回所有部门       
        public Dictionary<int, string> GetOrganizationUnits()
        {

            var orgunits = _organizationUnitAppService.GetOrganizationUnits();

            Dictionary<int, string> orgunitslist = new Dictionary<int, string>();

            foreach (OrganizationUnitDto org in orgunits.Result.Items)
            {
                orgunitslist.Add((int)org.Id, org.DisplayName);
            }
            return orgunitslist;
        }

        //返回岗位列表

        public Dictionary<int, string> GetPosts()
        {
            var posts = _postAppService.GetAllPosts();

            Dictionary<int, string> postslist = new Dictionary<int, string>();

            foreach (PostListDto post in posts.Result)
            {
                postslist.Add((int)post.Id, post.Name);
            }
            return postslist;
        }


    }
}
